package com.cgy.service.Impl;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.cgy.entity.ResStatistics;
import com.cgy.repository.ResStatisricsRepository;
import com.cgy.service.ResStatisticsService;
@Service
public class ResStatisticsServiceImpl implements ResStatisticsService {
@Autowired
private ResStatisricsRepository resReoisitory;
	@Override
	public Page<ResStatistics> findBynameResStatistics(ResStatistics r, Pageable pageable) {
		// TODO Auto-generated method stub
		return resReoisitory.findAll(get(r), pageable);
	}

	private Specification<ResStatistics> get(ResStatistics r) {
		// TODO Auto-generated method stub
		return new Specification<ResStatistics>() {

			@Override
			public Predicate toPredicate(Root<ResStatistics> root, CriteriaQuery<?> query,
					CriteriaBuilder criteriaBuilder) {
				// TODO Auto-generated method stub
				Predicate predicate = criteriaBuilder.conjunction();//动态sql表达式
				List<Expression<Boolean>> exList = predicate.getExpressions(); 
				return predicate;
			}
		};
	}
	@Transactional
	@Override
	public ResStatistics addAndUpdateResStatistics(ResStatistics r) {
		// TODO Auto-generated method stub
		return resReoisitory.saveAndFlush(r);
	}

	@Override
	public Integer deleteResStatistics(Integer rid) {
		// TODO Auto-generated method stub
		return resReoisitory.deleteResStatistics(rid);
	}

	@Override
	public List<ResStatistics> findAll() {
		// TODO Auto-generated method stub
		return resReoisitory.findAll(); 
	}


	@Override
	public Integer upCiShu(Integer zid, String month) {
		// TODO Auto-generated method stub
		return resReoisitory.upCiShu(zid, month);
	}


} 
